
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false"%>
<head>
    <title>${registrationNO}-视频回放</title>
    <%@ include file="videoHead.jsp"%> 
</head>
<body class="videoHk" onLoad="InitOcx()" onUnload="StopPlay(),DisConnect()">
<div class="videoPage">
	
	<div class="video-chart">
		<div class="video" style="border:double;background: url(${appCtx}resources/images/video/bg.jpg) #ededed no-repeat 50% 0;">
			<object	classid="clsid:EE4EA829-B8DA-4229-AC72-585AF45AD778" codebase="" standby="Waiting..." 
				id="ppvs1" width="100%" height="100%" name="ocx1" title="视频">
				<a class="toolBtn" href="${ocxPath}OcxHK.exe" id="downloadVideoControl">下载视频控件</a>
				
			</object>
		</div>
		<div class="chart">
		<div style="width:100%;height:30%;padding-top:10px;">
		
		<table class="table">
			<tr>
				<td>图片</td>
				<td>疲劳报警</td>
				<td>夜间行车</td>
				<td>超速报警</td>
				<td>道路类型超速报警</td>
			</tr>
			<tr>
				<td><a class="db" href="javascript:;" id="imageSpan" onclick="clickimageSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="tiredSpan" onclick="clicktiredSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="nightSpan" onclick="clicknightSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="speedSpan" onclick="clickspeedSpan()">-</a></td>
				<td><a class="db" href="javascript:;" id="roadLevelSpeedSpan" onclick="clickroadLevelSpeedSpan()">-</a></td>
			</tr>
		</table>
		</div>
		
		<div id="speedCharts" style="width:100%;height:70%"></div>
	</div>
	</div>
	<div class="map-track">
		<div id="gdMap"></div>
		<div id="speedDiv">
			<div id="trackList"></div>
		</div>
	</div>
</div>

<!-- 用于控制弹出窗口- -->
<a class="dn" id="txtOpenWindow" target="_self"></a>
<div id="tooldiv">
		
		<a class="toolBtn" href="javascript:;" style="display:none" id="btnStopVideoDownload" onclick="StopDownloadByTime()">停止视频下载</a>
		<a class="toolBtn" href="javascript:;" style="display:none" id="btnStopVideoReplay" onclick="StopPlayBack()">停止视频回放</a>
		<!-- <select style="width:130px;margin: 0px;" id="timeOutSel">
		<option value ="300" selected="selected">5分钟后关闭</option>
  		<option value ="600">10分钟后关闭</option>
  		<option value="1200">20分钟后关闭</option>
  		<option value="1800">30分钟后关闭</option>
  		</select>
  		<span id="t_m">00分</span> 
		<span id="t_s">00秒</span> -->
		<button class="btn dn" id="closeVideoDiv" >关闭视频</button>
		<button class="btn dn" id="downLoadVideoDiv" onclick="downLoadVideo()">下载视频</button>
		<a class="toolBtn" id="setVideoDiv" href="javascript:;" onclick="setVideo()" >查询</a>
		<select id="selectVehicleSel" onchange="changeVechile()"  style="width:100px;margin: 0px;">
		</select>
	</div>
	
<!-- Modal -->
<div id="myModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="width:300px;left: 90%;top:5%;">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">视频回放查询</h3>
  </div>
  <div class="modal-body">
    <ul class="videoTable">
				<li>设备ID：</li>
				<li class="bt10"><input type="text" id="devid" value="" disabled></li>
				<li>通道号：</li>
				<li class="bt10">
					<select id="ChannelNo" value=''>
						<option value="1" selected="selected">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
					</select>
				</li>
				<li>设备注册线路编号：</li>
				<li class="bt10">
					<select id="RegisterNo" value="">
						<option value="1" selected="selected">1</option>
						<option value="2">2</option>
						<option value="3">3</option>
						<option value="4">4</option>
					</select>
				</li>
				<li>码流类型：</li>
				<li class="bt10">
					<select id="StreamType" value="">
						<option value="0">主码流</option>
						<option value="1" selected="selected">子码流</option>
					</select>
				</li>
				<li>回放下载时间段：</li>
				<li class="bt10">
					<select onchange="changeBackSelect()" id="videoBack" value="">
					</select>
				</li>
				<li>开始时间：</li>
				<li class="bt10"><input type="text" class="Wdate" name="startDate" id="startDate" onclick="WdatePicker({isShowClear:false,dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'#F{$dp.$D(\'endDate\')}'})" />   </li>
				<li>结束时间：</li>
				<li class="bt10"><input type="text" class="Wdate" name="endDate" id="endDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startDate\')}',maxDate:'%y-%M-%d %H:%m:%s'})" />   </li>
				<li>进度条<span style="color:red;">：下载路径 D:\video\ </span>：
				</li>
			</ul>
			<div class="progress progress-striped active" style="width: 200px; margin-bottom: 10px; margin-left: 30px;">
  <div id="downbar" class="bar" style="width: 0%;"></div>
</div>
  </div>
  <div class="modal-footer">
  <a class="toolBtn" href="javascript:;" onclick="QueryDevRecordFiles()">查询</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnPlayBack"  >回放</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnDownloadByTime" >下载</a>
 	 &nbsp;&nbsp;
 	 <a class="toolBtn" href="javascript:;" id="btnVideoDown" data-dismiss="modal" aria-hidden="true" style="background-color: #0066cc;" >关闭</a>
  </div>
</div>
<script>

var oneDay = 10 * 1000;
var date = [];

var data = [];
var now = new Date();
var nowstr="";
var vehicleID ="${vehicleID}";	
var iConnHandle = -1;		//连接设备返回句柄
var iConnHandle2 = -1;
var iConnHandle3 = -1;
var iConnHandle4 = -1;
var iPlayHandle = -1;		//播放视频返回句柄
var iPlayHandle2 = -1;
var iPlayHandle3 = -1;
var iPlayHandle4 = -1;
var iChannel = 1;			//设备视频通道
var iStreamType = 1;		//取设备流类型	0：主码流	1：子码流
var iRegisterNo = 1;		//设备注册线路编号，以iVMS-7200平台添加设备时选择路线为标准，route1对应线路编号为1，route2对应线路编号为2,依次类推

var RegIp='${RegIp}';
var RegPort='${RegPort}';
var StreamIp='${StreamIp}';
var StreamPort='${StreamPort}';
var AlarmIp='${AlarmIp}';
var AlarmPort='${AlarmPort}';
var DeviceId='${DeviceId}'; 

var commno ="${commno}";
var regNO ="${registrationNO}";
var internal_number ="${internal_number}";


var obj = null;
var intsetInterval=0;
var isinitselect = true;
var  appCtx="${appCtx}";
var defaultTime =60;

var queryStartTime="";
var queryEndTime="";
var playStartTime="";
var playEndTime="";

var dataArray=new Array(); 
var videoCache = new HashMap();

var playfilename ="";

var imageAlarmArray=[];
var marketArray=[];
var lineListArray=[];

var videoImagesList=[];
var videoTiredAlarmList=[];
var videoNightAlarmList=[];
var videoSpeedAlarmList=[];
var videoRoadLevelSpeedAlarmList=[];

var isShowImages=false;
var isShowTireAlarm=false;
var isShowNightAlarm=false;
var isShowSpeedAlarm=false;
var isShowRoadAlarm=false;


var imagesList=[];
var tireAlarmList=[];
var nightAlarmList=[];
var speedAlarmList=[];
var roadAlarmList=[];

var alarmImages="http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png";
var map;
var myChart;
	

var option = {
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: date
    },
    grid:{
    	x:30,
    	y:30,
    	x2:10,
    	y2:10
    	
    },
    tooltip: {
        trigger: 'axis',
        formatter: function (params) {
            params = params[0];
            return "时间:"+params.name+"<br/>"+"速度"+params.value;
        },
        axisPointer: {
            animation: false
        }
    },
    yAxis: {
        boundaryGap: [0, '50%'],
        name : '速度(km/h)',
	    type : 'value',
	    max : 150,
    },
    series: [
        {
            name:'速度',
            type:'line',
            smooth:true,
            symbol: 'none',
            stack: 'a',
            data: data
        }
    ]
};

$(function(){ 
	try{
		map = new AMap.Map('gdMap', {
	        resizeEnable: true,
	        zoom:11,
	        center: [116.397428, 39.90923]
	    });
		
	    myChart = echarts.init(document.getElementById('speedCharts'));
		myChart.setOption(option);
		updatemyChart();
		
		 initVehicleList();
		 initTable();
//		 queryVehicleTrack();
		 $("#devid").val(DeviceId);
		 $("#startDate").val(getDay(1));
		 $("#endDate").val(getDay(0));
		 $("#btnPlayBack").unbind("click");
		 $("#btnPlayBack").bind("click",PlayBack);
		 $("#btnPlayBack").html("回放");

		 $("#btnDownloadByTime").unbind("click");
		 $("#btnDownloadByTime").bind("click",DownloadByTime);
		 $("#btnDownloadByTime").html("下载");
		 
		 /*defaultTime =$("#timeOutSel").val();
		 setTimeout("Play()", 3000 ); 
		 intsetInterval=window.setInterval("timeOut();", 1000);
		 $("#closeVideoDiv").unbind("click");
		 $("#closeVideoDiv").bind("click",buttonCloseVideo);
		 $("#closeVideoDiv").html("关闭视频") */
	}catch(e){
		  
	}
});

function updatemyChart() {
    myChart.setOption({
        xAxis: {
            data: date
        },
        series: [{
            name:'速度',
            data: data
        }]
    });
}

function initTable(){
	$("#trackList").flexigrid({
        dataType : 'json',
        colModel : [{
        	display : '序号',
            name : 'id',
            width : 50,
            sortable : true,
            align : 'left'
        },{
            display : '车牌号',
            name : 'registrationNO',
            width : 120,
            sortable : false,
            align : 'left'
        },{
            display : '自编号',
            name : 'internal_number',
            width : 120,
            sortable : false,
            align : 'left'
        },{
            display : '定位时间',
            name : 'gps_time',
            width : 150,
            sortable : false,
            align : 'left',    
        },{
            display : '里程(km)',
            name : 'gps_mileage',
            width : 100,
            sortable : false,
            align : 'left',    
        },{
            display : '速度(km/h)',
            name : 'gps_speed',
            width : 100,
            sortable : false,
            align : 'left',    
        },{
            display : '纬度',
            name : 'latitude',
            width : 120,
            sortable : false,
            align : 'left',    
        },{
            display : '经度',
            name : 'longitude',
            width : 120,
            sortable : false,
            align : 'left',    
        },{
            display : '位置信息',
            name : 'address',
            width : 235,
            sortable : false,
            align : 'left',
            paramcolnames : ['id','longitude','latitude','gps_time','gps_mileage','gps_speed'],
			handlefunction: getAddress
        }],
        resizable : false,
        sortname : "id",// 第一次加载数据时排序列
        sortorder : "asc",// 第一次加载数据时排序类型
        usepager : false,// 是否分页，默认为true。
        showToggleBtn : false,
        showTableToggleBtn : false,// 是否显示收起/打开按钮,默认不显示。
        rowId : 'id',// 多选框绑定行的id,只有checkbox : true时才有效。
        width : '80%',// 表格宽度
        titDisplay:false,
        onSuccess : function(data){
        	if(isToday(playEndTime)){
        		videoTiredAlarmList=[];
        		videoNightAlarmList=[];
        		videoSpeedAlarmList=[];
        		videoRoadLevelSpeedAlarmList=[];
        		$("#tiredSpan").html("-");
        		$("#nightSpan").html("-");
        		$("#speedSpan").html("-");
        		$("#roadLevelSpeedSpan").html("-");
        		if(data&&data.rows&&data.rows.length>0){
        			videoImagesList=data.rows[0].hisPicList;
        			$("#imageSpan").html(videoImagesList.length);
        		}
        	}else{
        		if(data&&data.rows&&data.rows.length>0){
        			videoImagesList=data.rows[0].hisPicList;
            		videoTiredAlarmList=data.rows[0].tiredAlarmList;
            		videoNightAlarmList=data.rows[0].nightAlarmList;
            		videoSpeedAlarmList=data.rows[0].speedAlarmList;
            		videoRoadLevelSpeedAlarmList=data.rows[0].roadLevelSpeedAlarmList;
            		$("#tiredSpan").html(videoTiredAlarmList.length);
            		$("#nightSpan").html(videoNightAlarmList.length);
            		$("#speedSpan").html(videoSpeedAlarmList.length);
            		$("#roadLevelSpeedSpan").html(videoRoadLevelSpeedAlarmList.length);
            		$("#imageSpan").html(videoImagesList.length);
            	}
        	}
        	
        	
        	if(lineListArray.length>1){
        		map.setCenter(new AMap.LngLat(lineListArray[0][0],lineListArray[0][1]));
  			 	var polyline = new AMap.Polyline({
  			        path: lineListArray,          //设置线覆盖物路径
  			        strokeColor: "#3366FF", //线颜色
  			        strokeOpacity: 1,       //线透明度
  			        strokeWeight: 5,        //线宽
  			        strokeStyle: "solid",   //线样式
  			        strokeDasharray: [10, 5] //补充线样式
  			    });
  			    polyline.setMap(map);
  		 	}
        	updatemyChart();
        },
        onSelectRow : function(row){
        	map.remove(marketArray);
        	marketArray=[];
        	map.setCenter(new AMap.LngLat(row.longitude, row.latitude));
        	
        	var marker = new AMap.Marker({
    	        map:map,
    	        position: [row.longitude, row.latitude],
    	        offset: new AMap.Pixel(-15, -10),
    	        icon: appCtx + "resources/images/mapTool/car1.png"
    	    });
    		var infoWindow = new AMap.InfoWindow({offset: new AMap.Pixel(0, -30)}); 
    		marker.content = '定位时间：'+row.gps_time+'</br>速度：'+row.gps_speed+' 公里/小时</br>里程：'+row.gps_mileage+' 公里';
    		marker.on('click', function(e){
    			 isopenWin=true;
    			 infoWindow.setContent(e.target.content);
    		     infoWindow.open(map, e.target.getPosition());
    		     
    		   	 
    		});
    		marketArray.push(marker);
    		marketArray.push(infoWindow);
        },
        onSelectAllRow : function(data){

        }
    });
}


function closeInfoWindow() {
    map.clearInfoWindow();
}

function clickimageSpan(){
	isShowImages=!isShowImages;
	if(isShowImages){ 
		if(videoImagesList.length>0){
			map.setCenter(new AMap.LngLat(videoImagesList[0].gdLng,videoImagesList[0].gdLat));
		for(var i=0;i<videoImagesList.length;i++){
			var marker = new AMap.Marker({
		        map: map,
		        position: [videoImagesList[i].gdLng,videoImagesList[i].gdLat]
		    });
			var infoWindow = new AMap.InfoWindow({isCustom: true,offset: new AMap.Pixel(0, -10)}); 
			marker.content = "<div style='padding:15px;border:1px solid #dedede;background:#fff;position:relative;'><a  onclick='closeInfoWindow()' style='position:absolute;top:3px;right:3px;background:url(http://webapi.amap.com/images/close2.gif) 0 0 no-repeat;width:10px;height:10px;' href='javascript:;'></a><img class='db' style='height:200px;weight:300px;' src='"+videoImagesList[i].imgUrl+"'><p style='padding-top:15px;'>拍照时间："+videoImagesList[i].gpsTimeStr+"</p></div>";
			marker.on('click', function(e){
				 isopenWin=true;
				 infoWindow.setContent(e.target.content);
			     infoWindow.open(map, e.target.getPosition());
			     
			   	 
			});
			imagesList.push(marker);
			imagesList.push(infoWindow);
		}
		}
		
	}else{
		map.remove(imagesList);
		imagesList=[];
	}
}



function clicktiredSpan(){
	isShowTireAlarm=!isShowTireAlarm;
	if(isShowTireAlarm){
		if(videoTiredAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoTiredAlarmList[0].sLon,videoTiredAlarmList[0].sLat));
			for(var i=0;i<videoTiredAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoTiredAlarmList[i].sLon,videoTiredAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "疲劳报警"+(i+1)+"</br> 开始时间："+videoTiredAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoTiredAlarmList[i].eLon,videoTiredAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "疲劳报警"+(i+1)+"</br> 结束时间："+videoTiredAlarmList[i].endTime
				});
				tireAlarmList.push(marker);
				tireAlarmList.push(marker1);
			}
		}
		
	}else{
		map.remove(tireAlarmList);	
		tireAlarmList=[];
	}
}

function clicknightSpan	(){
	isShowNightAlarm=!isShowNightAlarm;
	if(isShowNightAlarm){
		if(videoNightAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoNightAlarmList[0].sLon,videoNightAlarmList[0].sLat));
			for(var i=0;i<videoNightAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoNightAlarmList[i].sLon,videoNightAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "夜间行车"+(i+1)+"</br> 开始时间："+videoNightAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoNightAlarmList[i].eLon,videoNightAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "夜间行车"+(i+1)+"</br> 结束时间："+videoNightAlarmList[i].endTime
				});
				
				nightAlarmList.push(marker);
				nightAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(nightAlarmList);
		nightAlarmList=[];
	}
}

function clickspeedSpan(){
	isShowSpeedAlarm=!isShowSpeedAlarm;
	if(isShowSpeedAlarm){
		if(videoSpeedAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoSpeedAlarmList[0].sLon,videoSpeedAlarmList[0].sLat));
			for(var i=0;i<videoSpeedAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoSpeedAlarmList[i].sLon,videoSpeedAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "超速报警"+(i+1)+"</br> 开始时间："+videoSpeedAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoSpeedAlarmList[i].eLon,videoSpeedAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "超速报警"+(i+1)+"</br> 结束时间："+videoSpeedAlarmList[i].endTime
				});
				
				speedAlarmList.push(marker);
				speedAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(speedAlarmList);
		speedAlarmList=[];
	}
}

function clickroadLevelSpeedSpan(){
	isShowRoadAlarm=!isShowRoadAlarm
	if(isShowRoadAlarm){
		if(videoRoadLevelSpeedAlarmList.length>0){
			map.setCenter(new AMap.LngLat(videoRoadLevelSpeedAlarmList[0].sLon,videoRoadLevelSpeedAlarmList[0].sLat));
			for(var i=0;i<videoRoadLevelSpeedAlarmList.length;i++){
				var marker = new AMap.Marker({
				       position: [videoRoadLevelSpeedAlarmList[i].sLon,videoRoadLevelSpeedAlarmList[i].sLat],
				       icon: alarmImages
					});
				marker.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker.setTitle('报警信息');

				// 设置label标签
				marker.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "道路类型超速报警"+(i+1)+"</br> 开始时间："+videoRoadLevelSpeedAlarmList[i].startTime
				});
				var marker1 = new AMap.Marker({
				       position: [videoRoadLevelSpeedAlarmList[i].eLon,videoRoadLevelSpeedAlarmList[i].eLat],
				       icon: alarmImages
					});
				marker1.setMap(map);
				// 设置鼠标划过点标记显示的文字提示
				marker1.setTitle('报警信息');

				// 设置label标签
				marker1.setLabel({//label默认蓝框白底左上角显示，样式className为：amap-marker-label
				        offset: new AMap.Pixel(20, 20),//修改label相对于maker的位置
				        content: "道路类型超速报警"+(i+1)+"</br> 结束时间："+videoRoadLevelSpeedAlarmList[i].endTime
				});
				
				roadAlarmList.push(marker);
				roadAlarmList.push(marker1);
			}
		}
	}else{
		map.remove(roadAlarmList);
		roadAlarmList=[];
	}
}


function isToday(str){
	var d=new Date(Date.parse(str.replace(/\-/g, "\/")));
	if (d.toDateString() == new Date().toDateString()){
		return true;
	}else{
		return false;
	}
}


function showAddress(id,lon,lat){
	var ctrl="#address_"+id;
	var geocoder = new AMap.Geocoder({
        radius: 1000,
        extensions: "all"
    });        
    geocoder.getAddress(new AMap.LngLat(lon,lat), function(status, result) {
        if (status === 'complete' && result.info === 'OK') {
        	var address=result.regeocode.formattedAddress;
        	$(ctrl).text(address);
        }
    });  
}
function getAddress(id,lon,lat,gps_time,gps_mileage,gps_speed){
	date.push(gps_time);
	data.push(gps_speed);
	
	 var arrgps=[];
		 arrgps.push(lon);
		 arrgps.push(lat);
	lineListArray.push(arrgps);
	showAddress(id,lon,lat);
	return '<span id="address_' + id + '">'+'</span>';
};
function initVehicleList(){
	$.ajax({
		type : 'post',
		async : false,
		url : appCtx + "/video/queryVideoVehicleList.html",
		cache : false,
		dataType : "JSON",
		success : function(data) {
			if(data){

				$('#selectVehicleSel').select2({
				  data: data
				})
				
				$('#selectVehicleSel').val(vehicleID).trigger("change");
			}
		}
	});

}

function timeOut(){
	if(defaultTime>0){
		defaultTime--;
		var m=Math.floor(defaultTime/60%60); 
		var s=Math.floor(defaultTime%60);
		if(m<10){
			document.getElementById("t_m").innerHTML = "0"+m + "分"; 
		}else{
			document.getElementById("t_m").innerHTML = m + "分"; 
		}
		if(s<10){
			document.getElementById("t_s").innerHTML = "0"+s + "秒";
		}else{
			document.getElementById("t_s").innerHTML = s + "秒";
		}
	}else{
		document.getElementById("t_m").innerHTML = "00" + "分";
		document.getElementById("t_s").innerHTML = "00" + "秒";
		window.clearInterval(intsetInterval);
		StopPlay();  
		$("#closeVideoDiv").unbind("click");
		$("#closeVideoDiv").bind("click",buttonOpenVideo);
		$("#closeVideoDiv").html("打开视频")
	}
}

function buttonOpenVideo(){
	 defaultTime =$("#timeOutSel").val();
	 Play();
	 intsetInterval=window.setInterval("timeOut();", 1000);
	 $("#closeVideoDiv").unbind("click");
	 $("#closeVideoDiv").bind("click",buttonCloseVideo);
	 $("#closeVideoDiv").html("关闭视频")
}
function buttonCloseVideo(){
	defaultTime=0;
	document.getElementById("t_m").innerHTML = "00" + "分";
	document.getElementById("t_s").innerHTML = "00" + "秒";
	window.clearInterval(intsetInterval);
	StopPlay(); 
	$("#closeVideoDiv").unbind("click");
	$("#closeVideoDiv").bind("click",buttonOpenVideo);
	$("#closeVideoDiv").html("打开视频")
}

function setTimeOut(){
	 Play();
	 $("#resetTimeout").hide();
	 $("#time_label").show();
	defaultTime = videoOverTime;
}

    

//初始化控件
function InitOcx()
{

		try
		{
			//根据控件的PorgID来判断是否注册，未注册则抛出异常
			obj = new ActiveXObject("ppvsGUARD.ppvsguardCtrl.1");
			
			//设置窗口模式
			var PlayOCX = document.getElementById("ppvs1");
		/* 	var PlayOCX2 = document.getElementById("ppvs2");
			var PlayOCX3 = document.getElementById("ppvs3");
			var PlayOCX4 = document.getElementById("ppvs4"); */
			
			if ( typeof PlayOCX == "undefined" || PlayOCX == null )
			{
				//document.getElementById("ShowMessage").value = "控件已注册但页面对象不存在！\r\n";
				console.log("控件已注册但页面对象不存在！");
				return;
			}
			PlayOCX.SetActiveXShowMode(0,0);//实时预览模式，需要修改模式或者窗口UI可参考SetActiveXShowMode接口说明
		/* 	PlayOCX2.SetActiveXShowMode(0,0);
			PlayOCX3.SetActiveXShowMode(0,0);
			PlayOCX4.SetActiveXShowMode(0,0); */
			//document.getElementById("ShowMessage").value = "控件已注册并初始化完成！\r\n";
			console.log("控件已注册并初始化完成！");
			ConnDevice();
		}
		catch ( e )
		{
			//document.getElementById("ShowMessage").value = "控件未注册或未安装！\r\n";
			console.log("控件未注册或未安装！");
		}

}

//连接设备
function ConnDevice()
{
	//设备注册信息
	var szAccount = DeviceId;
	//注册服务IP、端口
	var szRegIP = RegIp;
	var iRegPort = RegPort;

	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
/* 	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4"); */
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册！\r\n";
		console.log("控件未注册！");
		return;
	}
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	
	if ( typeof szAccount == "undefined" || szAccount == null || szAccount == "")
	{
		//document.getElementById("ShowMessage").value = PreText + "设备ID不能为空！\r\n";
		console.log("设备ID不能为空！");
		return;
	}
	var ShowMsg = "停止预览失败！\r\n";
	iConnHandle = PlayOCX.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
/* 	iConnHandle2=PlayOCX2.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
	iConnHandle3=PlayOCX3.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345");
	iConnHandle4=PlayOCX4.ConnectDeviceByACS(szAccount, szRegIP, iRegPort, "admin", "12345"); */

	if (iConnHandle < 0)
	{
		ShowMsg = "连接设备失败！\r\n";
	}
	else
	{
		ShowMsg = "连接设备成功！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}

//实时预览
function Play()
{
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在预览中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log(ShowMsg);
		return;
	}
	
	var szAccount = DeviceId;
	//iChannel = document.getElementById("ChannelNo").value;
	iRegisterNo = 2;
	//流媒体服务器信息
	var szStreamServerIP = StreamIp;
	var iStreamServerPort = StreamPort;
	
	//有视频播放，则先停止
	if( iPlayHandle>0 )
	{
		StopPlay();
	}
	//设置设备注册线路编号，以iVMS-7200添加设备选择注册线路匹配
	PlayOCX.SetDeviceNetLine(iRegisterNo);
	PlayOCX2.SetDeviceNetLine(iRegisterNo);
	PlayOCX3.SetDeviceNetLine(iRegisterNo);
	PlayOCX4.SetDeviceNetLine(iRegisterNo);
	//取流类型
	iStreamType = 1;
	
	//客户端到流媒体采用TCP，流媒体到设备采用TCP取流
	iPlayHandle = PlayOCX.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 1, iStreamType, 1);
	iPlayHandle2=PlayOCX2.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 2, iStreamType, 1);
	iPlayHandle3=PlayOCX3.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 3, iStreamType, 1);
	iPlayHandle4=PlayOCX4.StreamPlayStartByTCP(szStreamServerIP, iStreamServerPort, szAccount, 4, iStreamType, 1);
			
	if (-1 == iPlayHandle)
	{
		ShowMsg = "预览失败！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log("预览失败！");
		return;		
	}	
		
	//设置窗口的设备信息显示
	//var szMode = "TCP";
	//PlayOCX.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX2.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX3.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
	//PlayOCX4.SetDeviceInfoForShow( ">>> 转发取流("+szMode+") <<<" );
}

//停止预览
function StopPlay()
{	
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	var PlayOCX2 = document.getElementById("ppvs2");
	var PlayOCX3 = document.getElementById("ppvs3");
	var PlayOCX4 = document.getElementById("ppvs4");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}

	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	var ShowMsg = "停止预览失败！\r\n";
	if( iPlayHandle >= 0 )
	{
		if(PlayOCX.StreamPlayStopByTCP())
		{
			iPlayHandle = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle2 >= 0){
		if(PlayOCX2.StreamPlayStopByTCP())
		{
			iPlayHandle2 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle3 >= 0){
		if(PlayOCX3.StreamPlayStopByTCP())
		{
			iPlayHandle3 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	if(iPlayHandle4 >= 0){
		if(PlayOCX4.StreamPlayStopByTCP())
		{
			iPlayHandle4 = -1;
			ShowMsg = "预览已停止！\r\n"
		}
	}
	else
	{
		ShowMsg = "预览未开启！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}

//断开与设备连接
function DisConnect()
{
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}

	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}

	var ShowMsg = "与设备断开连接失败！\r\n";
	if( iConnHandle>0 )
	{
		if( PlayOCX.DisConnectDevice() )
		{
			iConnHandle = -1;
			ShowMsg = "与设备已断开连接！\r\n";
		}
	}
	else
	{
		ShowMsg = "设备未连接！\r\n";
	}
	//document.getElementById("ShowMessage").value = PreText + ShowMsg;
	console.log(ShowMsg);
}





//查询设备录像文件
function QueryDevRecordFiles()
{
	map.remove(marketArray);
	map.remove(imageAlarmArray);
	map.remove(imagesList);
	map.remove(tireAlarmList);
	map.remove(nightAlarmList);
	map.remove(speedAlarmList);
	map.remove(roadAlarmList);
	imagesList=[];
	tireAlarmList=[];
	nightAlarmList=[];
	speedAlarmList=[];
	roadAlarmList=[];
	imageAlarmArray=[];
	marketArray=[];
	lineListArray=[];
	videoImagesList=[];
	videoTiredAlarmList=[];
	videoNightAlarmList=[];
	videoSpeedAlarmList=[];
	videoRoadLevelSpeedAlarmList=[];
	date = [];
	data = [];
	
	queryStartTime=$.trim($('#startDate').val());
	queryEndTime=$.trim($('#endDate').val());
	
	dataArray=[];
	videoCache.clear();
	var obj=document.getElementById('videoBack'); 
	obj.options.length=0;
	

	var ShowMsg = "请先连接设备，并确保连接成功！\r\n";
	//var PreText = document.getElementById("ShowMessage").value;
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log(ShowMsg);
		return;
	}
	iChannel = document.getElementById("ChannelNo").value;
	var szInfo = PlayOCX.PlaybackSearchFile(iChannel,0,queryStartTime, queryEndTime);
	//<?xml version='1.0'?>\r\n<SearchRemoteRecordFile>\r\n<File>\r\n<FileName>ch01_00100135000000</FileName>\r\n<StartTime>2013-12-10 10:03:00</StartTime>\r\n<StopTime>2013-12-10 10:20:08</StopTime>\r\n<FileSize>247238892</FileSize>\r\n<FileType>0</FileType>\r\n</File>\r\n</SearchRemoteRecordFile>
	//var szInfo = "<?xml version='1.0'?>\r\n<SearchRemoteRecordFile/>";
	var xmlDoc=loadXML(szInfo);
	var elements = xmlDoc.getElementsByTagName("File");
	if(elements.length==0){
		alert("没有找到查询日期内的视频资料！");
		return;
	}
	for (var i = 0; i < elements.length; i++) {
		var fileData= new Object();
      var fileName = elements[i].getElementsByTagName("FileName")[0].firstChild.nodeValue;
      fileData.FileName=fileName;
      var fileSize = elements[i].getElementsByTagName("FileSize")[0].firstChild.nodeValue; 
      fileData.FileSize=fileSize;
      var startTime = elements[i].getElementsByTagName("StartTime")[0].firstChild.nodeValue; 
      fileData.startTime=startTime;
      var stopTime = elements[i].getElementsByTagName("StopTime")[0].firstChild.nodeValue; 
      fileData.stopTime=stopTime;
      fileData.Channel=iChannel;
      var videoBackSelect=document.getElementById("videoBack");
      
      var a=new Option();
      a.value=fileName;
      a.text=startTime;
      videoBackSelect.options.add(a);
      dataArray.push(fileData);
      videoCache.put(fileName,fileData);
	}
	playStartTime=dataArray[0].startTime;
	playEndTime=dataArray[0].stopTime;
	
	playfilename=dataArray[0].FileName;
	///var fileflag=elements[0].getElementsByTagName("FileName")[0].firstChild.nodeValue;
	//$("#filename").val(fileflag);
	var ShowMsg = "";
	if ( typeof szInfo != "undefined" && szInfo != null && szInfo != "")
	{
		//ShowMsg = PreText + "查询录像文件信息:\r\n" + szInfo + "\r\n";
	}
	else
	{
		//ShowMsg = PreText + "查询录像文件信息态失败!" + "\r\n";
	}
	//document.getElementById("ShowMessage").value = ShowMsg;
}

//按文件回放,如果需要拖放或者快进慢放等，可调用PlaybackControl接口完成
function PlayBack()
{

//	queryVehicleTrack();
	map.remove(marketArray);
	map.remove(imageAlarmArray);
	map.remove(imagesList);
	map.remove(tireAlarmList);
	map.remove(nightAlarmList);
	map.remove(speedAlarmList);
	map.remove(roadAlarmList);
	imagesList=[];
	tireAlarmList=[];
	nightAlarmList=[];
	speedAlarmList=[];
	roadAlarmList=[];
	imageAlarmArray=[];
	marketArray=[];
	lineListArray=[];
	videoImagesList=[];
	videoTiredAlarmList=[];
	videoNightAlarmList=[];
	videoSpeedAlarmList=[];
	videoRoadLevelSpeedAlarmList=[];
	date = [];
	data = [];
	
	
	if(!playfilename){
		alert("请先查询，选择回放或下载时间段！");
		return;
	}
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在回放中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		console.log("控件未注册或未安装！");
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		console.log("控件已注册但页面对象不存在！");
		return;
	}
	
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		document.getElementById("ShowMessage").value = PreText + ShowMsg;
		console.log("ShowMsg");
		return;
	}
	
	$("#btnPlayBack").unbind("click");
	$("#btnPlayBack").bind("click",StopPlayBack);
	$("#btnPlayBack").html("停止");
	$("#btnStopVideoReplay").css("display","inline-block");
	queryVehicleTrack();
	 
	iChannel = document.getElementById("ChannelNo").value;
	var fileinfo=videoCache.get(playfilename);
	//console.log(fileinfo.FileName);
	//console.log(fileinfo.FileSize);
	PlayOCX.StartPlaybackByFile(fileinfo.Channel,fileinfo.FileName,fileinfo.FileSize);//录像文件信息需要与实际查询QueryDevRecordFiles返回一致，此处仅为样例
}

function StopPlayBack()
{
	if ( typeof obj == "undefined" || obj == null )
	{
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		return;
	}
	
	$("#btnPlayBack").unbind("click");
	$("#btnPlayBack").bind("click",PlayBack);
	$("#btnPlayBack").html("回放")
	$("#btnStopVideoReplay").css("display","none");
	PlayOCX.StopPlaybackByFile();
}

var DownloadHandle = -1; 
function DownloadByTime()
{
	if(!playfilename){
		alert("请先查询，选择回放或下载时间段！");
		return;
	}
	//var PreText = document.getElementById("ShowMessage").value;
	var ShowMsg = "正在下载中...\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		//document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		return;
	}
	
	if (iConnHandle < 0)
	{
		ShowMsg = "请先连接设备，并确保连接成功！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		return;
	}
	
	//录像文件信息需要与实际查询QueryDevRecordFiles返回一致，此处仅为样例
	iChannel = document.getElementById("ChannelNo").value;
	var fileinfo=videoCache.get(playfilename);
	var filePath="D:\\video\\"+fileinfo.FileName+".mp4";
	DownloadHandle = PlayOCX.StartDownloadFileByTime(fileinfo.Channel,fileinfo.FileName,fileinfo.FileSize, filePath, fileinfo.startTime,fileinfo.stopTime, fileinfo.startTime, fileinfo.stopTime);
	if ( DownloadHandle > 0 )
	{
		//document.getElementById("ShowMessage").value = PreText + ShowMsg;
		alert("下载成功！");
		$("#btnDownloadByTime").unbind("click");
		$("#btnDownloadByTime").bind("click",StopDownloadByTime);
		$("#btnDownloadByTime").html("停止");
		$("#btnStopVideoDownload").css("display","inline-block");
		intsetInterval=window.setInterval("GetDownloadPos();", 2000);
	}
	else
	{
		if(DownloadHandle==-1){
			alert("下载失败！");
		}else if(DownloadHandle==-2){
			alert("容量不足！");
		}else if(DownloadHandle==-3){
			alert("未连接设备！");
		}else if(DownloadHandle==-4){
			alert("时间格式有误！");
		}else if(DownloadHandle==-5){
			alert("前端下载繁忙稍后再试");
		}else if(DownloadHandle==-6){
			alert("不支持下载此内容！");
		}else{
			alert("联系管理员");
		}
		
		//ShowMsg = "下载失败：" + DownloadHandle + "！\r\n";
		//document.getElementById("ShowMessage").value = PreText + ShowMsg; 
	}  
}


function GetDownloadPos()
{
	var PreText = "";
	var ShowMsg = "请先确认正在下载！\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		return;
	}
	
	if (DownloadHandle < 0)
	{
		return;
	}
	var DownloadPos = PlayOCX.GetDownloadPos(DownloadHandle);
	
	if(DownloadPos==100){
		 window.clearInterval(intsetInterval);
		 StopDownloadByTime();
	}
	
	$("#downbar").css("width",DownloadPos+"%")
//	alert("当前下载进度  "+DownloadPos+"% !");

}

function StopDownloadByTime()
{
	var PreText ="";
	var ShowMsg = "已停止下载！\r\n";
	if ( typeof obj == "undefined" || obj == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件未注册或未安装！\r\n";
		return;
	}
	
	var PlayOCX = document.getElementById("ppvs1");
	if ( typeof PlayOCX == "undefined" || PlayOCX == null )
	{
		document.getElementById("ShowMessage").value = PreText + "控件已注册但页面对象不存在！\r\n";
		return;
	}
	PlayOCX.StopDownloadFile(DownloadHandle);
	$("#btnDownloadByTime").unbind("click");
	 $("#btnDownloadByTime").bind("click",DownloadByTime);
	 $("#btnDownloadByTime").html("下载");
	 $("#btnStopVideoDownload").css("display","none");
	 window.clearInterval(intsetInterval);
	DownloadHandle = -1;
}


function addData(shift) {
    var hourstr=now.getHours() < 10 ? "0" + now.getHours() : now.getHours();
    var minutestr=now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes();
    var secondstr=now.getSeconds() < 10 ? "0" + now.getSeconds() : now.getSeconds();
    nowstr = [hourstr, minutestr, secondstr].join(':');
    date.push(nowstr);
    data.push(parseFloat(Math.random() * 30+50).toFixed(1));

    if (shift) {
        date.shift();
        data.shift();
    }

    now = new Date(+new Date(now) + oneDay);
}





	
//打开新窗体
function openWindow(url){
	var openLink = $("#txtOpenWindow");
	openLink.attr('href', url);
	openLink[0].click();
}

function changeVechile(){
	if(isinitselect){
		isinitselect=false;
	}else{

			try{
				exitstopplay();
			}catch(e){
				
			}
			
			var vid=$("#selectVehicleSel").val();
			openWindow(appCtx + "/video/hisVideo.html?vehicleID="+vid);
		
		
	}
}

function downLoadVideo(){
	
}

function setVideo(){
	$('#myModal').modal('show');
}

function closeVideo(){
	$('#myModal').modal('hide');
}

/**
 * 获取今天之前的日期
 * @param day
 */
function getDay(day){
	var today = new Date(); 
	return getCalcuDay(today,day);
}
/**
 * 获取指定日期的前几天
 * @param today
 * @param day
 * @returns {String}
 */
function getCalcuDay(today,day){
    var targetday_milliseconds=today.getTime() - 1000*60*60*24*day;          

    today.setTime(targetday_milliseconds); //注意，这行是关键代码    
      
    var tYear = today.getFullYear();  
    var tMonth = today.getMonth();  
    var tDate = today.getDate();  
    var tHuors= today.getHours();
    var tMinutes= today.getMinutes();
    var tSeconds= today.getSeconds();
    
    tMonth = doHandleMonth(tMonth + 1);  
    tDate = doHandleMonth(tDate);  
    tHuors = doHandleMonth(tHuors);  
    tMinutes = doHandleMonth(tMinutes);  
    tSeconds = doHandleMonth(tSeconds); 
    return tYear+"-"+tMonth+"-"+tDate+" "+tHuors+":"+tMinutes+":"+tSeconds;  
} 
function doHandleMonth(month){  
    var m = month;  
    if(month.toString().length == 1){  
       m = "0" + month;  
    }  
    return m;  
} 

var loadXML = function(xmlString){
    var xmlDoc=null;
    //判断浏览器的类型
    //支持IE浏览器 
    if(!window.DOMParser && window.ActiveXObject){   //window.DOMParser 判断是否是非ie浏览器
        var xmlDomVersions = ['MSXML.2.DOMDocument.6.0','MSXML.2.DOMDocument.3.0','Microsoft.XMLDOM'];
        for(var i=0;i<xmlDomVersions.length;i++){
            try{
                xmlDoc = new ActiveXObject(xmlDomVersions[i]);
                xmlDoc.async = false;
                xmlDoc.loadXML(xmlString); //loadXML方法载入xml字符串
                break;
            }catch(e){
            }
        }
    }
    //支持Mozilla浏览器
    else if(window.DOMParser && document.implementation && document.implementation.createDocument){
        try{
            /* DOMParser 对象解析 XML 文本并返回一个 XML Document 对象。
             * 要使用 DOMParser，使用不带参数的构造函数来实例化它，然后调用其 parseFromString() 方法
             * parseFromString(text, contentType) 参数text:要解析的 XML 标记 参数contentType文本的内容类型
             * 可能是 "text/xml" 、"application/xml" 或 "application/xhtml+xml" 中的一个。注意，不支持 "text/html"。
             */
            domParser = new  DOMParser();
            xmlDoc = domParser.parseFromString(xmlString, 'text/xml');
        }catch(e){  
        }
    }
    else{
        return null;
    }

    return xmlDoc;
}

function changeBackSelect(){
	var keyname=$("#videoBack").val();
	var objVideo=videoCache.get(keyname);
	playfilename=keyname;
	playStartTime=objVideo.startTime;
	playEndTime=objVideo.stopTime;
}

function queryVehicleTrack(){
	 var paramsGrid = [{
        name : 'vehicleID',
        value : vehicleID
    },{
        name : 'startTime',
        value : playStartTime
    },{
        name : 'endTime',
        value : playEndTime
    },{
        name : 'registrationNO',
        value : regNO
    },{
        name : 'internal_number',
        value : internal_number
    }];
 
	
	$("#trackList").flexOptions({
		url : appCtx + "/video/queryVideoVehicleTrackListForGrid.html",
		newp : 1,// 设置起始页
		params : paramsGrid
	}).flexReload();// 重新加载  
	

}
</script>
</body>
</html>
